package com.zhou.bpm.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhou.bpm.entity.BpmNode;
import com.zhou.bpm.entity.BpmProcess;
import com.zhou.bpm.mapper.BpmProcessMapper;
import com.zhou.bpm.service.IBpmNodeService;
import com.zhou.bpm.service.IBpmProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.zhou.bpm.enmu.NodeApproveType.PARALLEL_APPROVAL;
import static com.zhou.common.Constants.APPLY;

/**
 * @Author: zhoujinchuan
 * @Description: TODO（请添加描述）
 * @CreateTime: 2023/10/25 10:35
 */
@Service
public class BpmProcessServiceImpl extends ServiceImpl<BpmProcessMapper, BpmProcess> implements IBpmProcessService {

    @Autowired
    private IBpmNodeService bpmNodeService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveOrUpdatePlus(BpmProcess bpmProcess) {
        saveOrUpdate(bpmProcess);
        if (ObjectUtil.isNull(bpmProcess)){
            BpmNode entity = new BpmNode();
            entity.setApproveType(PARALLEL_APPROVAL.getCode());
            entity.setProcessCode(bpmProcess.getProcessCode());
            entity.setNodeCode(APPLY);
            entity.setNodeName("申请人节点");
            entity.setOrderNum(0);
            bpmNodeService.save(entity);
        }
    }
}
